package com.itzhigui.config;

import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.web.servlet.config.annotation.EnableWebMvc;
import springfox.documentation.builders.ApiInfoBuilder;
import springfox.documentation.builders.PathSelectors;
import springfox.documentation.builders.RequestHandlerSelectors;
import springfox.documentation.service.ApiInfo;
import springfox.documentation.service.Contact;
import springfox.documentation.spi.DocumentationType;
import springfox.documentation.spring.web.plugins.Docket;
import springfox.documentation.swagger2.annotations.EnableSwagger2;

/**
 * swagger2自身的配置类
 */
@Configuration
@EnableSwagger2 // 开启swagger2功能
@EnableWebMvc //开启mvc, springboot2.6.5以上版本需要添加下面的注解
public class SwaggerConfig {
    //向IOC容器中注册Docket
//    @Bean
//    public Docket docket(){
//        return new Docket(DocumentationType.SWAGGER_2)
//                .select()
//                .apis(RequestHandlerSelectors.any())
//                .apis(RequestHandlerSelectors.basePackage("com.itzhigui.controller"))
//                .paths(PathSelectors.any())
//                .build().apiInfo(apiInfo());
//    }
    // 前台接口分组
    @Bean
    public Docket docketApi(){
        return new Docket(DocumentationType.SWAGGER_2)
                .select()
                .apis(RequestHandlerSelectors.any())
                .apis(RequestHandlerSelectors.basePackage("com.itzhigui.controller.api"))
                .paths(PathSelectors.any())
                .build().apiInfo(apiInfo())
                .groupName("前台接口");
    }

    // 后台接口分组
    @Bean
    public Docket docketAdmin(){
        return new Docket(DocumentationType.SWAGGER_2)
                .select()
                .apis(RequestHandlerSelectors.any())
                .apis(RequestHandlerSelectors.basePackage("com.itzhigui.controller.admin"))
                .paths(PathSelectors.any())
                .build().apiInfo(apiInfo())
                .groupName("后台接口");
    }

    /**
     * 接口的一些说明信息
     * @return
     */
    private ApiInfo apiInfo() {
        return new ApiInfoBuilder()
                //指定标题
                .title("itzhigui项目接口文档")
                //接口信息描述
                .description("itzhigui项目接口测试")
                //指定swagger版本
                .version("0.0.1")
                //指定接口的联系人
                .contact(new Contact("itzhigui","http://www.itzhigui.com","485999155@qq.com"))
                .termsOfServiceUrl("")
                .license("")
                .build();

    }
}
